package com.promis.party.ui.partyactivity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;

import com.promis.party.R;
import com.promis.party.helper.ContextHelper;
import com.promis.party.ui.home.homebanner.threemmeetingonecourse.ThreeMeetingOneCourseActivity;
import com.promis.widget.ImageTextView;
import com.promis.widget.recycler.LinearSpacingItemDecoration;
import com.promis.widget.recycler.RecyclerLayoutManagerHelper;

/**
 * Created by zcy on 2018/9/25.
 */

public class PartyActivityFragment extends Fragment {

    private ContextHelper contextHelper;

    private PartyActivityListAdapter adapter;
    private RecyclerView recyclerView;

    private ImageTextView imgvThreeMeetingOneCourse;
    private ImageTextView imgvActivities;
    private ImageTextView imgvTodayTopNews;
    private ImageTextView imgvZuGongTopNews;
    private ImageTextView imgvJiangHauTopNews;
    private ImageTextView imgvHuoDongTopNews;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        FrameLayout rootLayout = (FrameLayout) inflater.inflate(R.layout.fragment_party_activity, container, false);

        recyclerView = rootLayout.findViewById(R.id.fragment_party_activity_rcyv);
        imgvThreeMeetingOneCourse = rootLayout.findViewById(R.id.fragment_party_activity_txtv_daily_renwujiaoban);
        imgvActivities = rootLayout.findViewById(R.id.fragment_party_activity_txtv_zhibuhuodong);
        imgvTodayTopNews = rootLayout.findViewById(R.id.fragment_party_activity_txtv_jinritoutiao);
        imgvZuGongTopNews = rootLayout.findViewById(R.id.fragment_party_activity_txtv_zugongtoutiao);
        imgvJiangHauTopNews = rootLayout.findViewById(R.id.fragment_party_activity_txtv_jianghuatoutiao);
        imgvHuoDongTopNews = rootLayout.findViewById(R.id.fragment_party_activity_txtv_huodongtoutiao);

        initData();
        initListener();
        return rootLayout;
    }

    private void initData() {
        contextHelper = new ContextHelper(getContext());

        RecyclerLayoutManagerHelper.buildVerticalLinearLayoutManager(getContext(), recyclerView);
        recyclerView.addItemDecoration(new LinearSpacingItemDecoration(getContext(), LinearLayoutManager.VERTICAL, 0, R.color.split_line));
        adapter = new PartyActivityListAdapter(getContext());
        recyclerView.setAdapter(adapter);
    }

    private void initListener() {
        imgvThreeMeetingOneCourse.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(getContext(), ThreeMeetingOneCourseActivity.class);
                startActivity(intent);
            }
        });

        imgvActivities.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(getContext(), ThreeMeetingOneCourseActivity.class);
                intent.putExtra("zhibuhuodong", "zhibuhuodong");
                startActivity(intent);
            }
        });

        imgvTodayTopNews.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(getContext(), TopNewsActivity.class);
                intent.putExtra("today", "today");
                startActivity(intent);
            }
        });

        imgvZuGongTopNews.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(getContext(), TopNewsActivity.class);
                intent.putExtra("zudang", "zudang");
                startActivity(intent);
            }
        });

        imgvJiangHauTopNews.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(getContext(), TopNewsActivity.class);
                intent.putExtra("jianghua", "jianghua");
                startActivity(intent);
            }
        });

        imgvHuoDongTopNews.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(getContext(), TopNewsActivity.class);
                intent.putExtra("huodong", "huodong");
                startActivity(intent);
            }
        });
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode == Activity.RESULT_OK) {
            switch (requestCode) {
//                case RequestCode.CITY : LetterSortActivity.Helper.onActivityResult(data, txtvCity); break;
//                case RequestCode.PETSELFISH :findOwnerPet(); break;
            }
        }
    }

    @Override
    public void onResume() {
        super.onResume();
    }

//    public void httpFindDynamicList() {
//        HttpJsonParams params = new HttpJsonParams();
//        params.add("interest",1);
//        if (UserPreferences.getInstance(getContext()).exists()) {
//            params.add("userId", UserPreferences.getInstance(getContext()).getId());
//        }
//        String url = contextHelper.getServiceUrl(R.string.findInterestDynamicList);
//        new HttpClient<JsonList<Dynamic>>(getContext()) {
//            @Override
//            protected void onSuccess(JsonList<Dynamic> result) {
//                dynamicList = result.getDataList();
//                adptAdopt.notifyDataSetChanged(dynamicList);
//            }
//        }.postAsyn(url, params);
//    }
}